#pragma once
#include "Thread.h"
#include "Download_i.h"

#define DOWNLOAD_MESSAGE_BASE (WM_USER + 4300)




class CDownloadThreadWorker
	: public IWorkThread
{
public:
	CDownloadThreadWorker(void);
	~CDownloadThreadWorker(void);
	void AppendTask(DownLoadTaskID taskID,const std::string& ip,const std::wstring& srcFile,const std::wstring& dstFile,bool isForceUpdate,bool isShow,INT64 from=-1);
	INT64 CancleTask(DownLoadTaskID taskID);
	//IWorkThread
	virtual UINT Run(HANDLE hThreadEndEvent, HWND hwndMessageWindow);
	virtual LPCWSTR GetDestFile();
	virtual LPCWSTR GetSourceFile();	
protected:
typedef	struct  tgDownLoadTask
	{
		DownLoadTaskID taskID;
		std::string ip;
		std::wstring srcFile;
		std::wstring dstFile;
		bool isForceUpdate;
		bool isShow;
		INT64 from;
		tgDownLoadTask()
		{
			taskID = INVALID_DOWNLOAD_TASK_ID;
			isForceUpdate = false;
			isShow = false;
			from = -1;
		}
	}DownLoadTask;
protected:
	bool DownloadHTTP(DownLoadTaskID TaskID, HWND hwndMessageWindow,const std::string& ip,const std::wstring& srcFile,const std::wstring& dstFile,bool isForceUpdate,bool isShow,INT64 from=-1);

public:
	INT64 m_lCurDownloadByte;
protected:
	
	const static int TIMEOUT = 30000;
	DownLoadTask m_stTask;
	UINT m_uResultID;
	HWND m_hwndMessageWindow;	
	bool m_bRun;
	HANDLE m_hCurrentFile;
	size_t m_nMaxRetry;
	size_t m_nRetryTimes;
};
